package com.macro.mall.tiny.modules.foster.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.common.api.CommonPage;
import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.foster.model.Appointment;
import com.macro.mall.tiny.modules.foster.service.AppointmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuyi
 * @since 2024-04-03
 */
@Api(tags = "AppointmentController", description = "预约管理")
@RestController
@RequestMapping("/foster/appointment")
@CrossOrigin
public class AppointmentController {
    private static final Logger LOGGER = LoggerFactory.getLogger(AppointmentController.class);
    @Autowired
    private AppointmentService appointmentService;
    /**
     * 分页查询预约信息
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("分页查询预约信息")
    @PreAuthorize("hasAnyAuthority('user','admin')")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<Appointment>> list(@RequestParam(value = "pageNum", defaultValue = "1")
                                               @ApiParam("页码") Integer pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "5")
                                               @ApiParam("每页数量") Integer pageSize){
        Page<Appointment> pageResult = appointmentService.pageAppointment(pageNum, pageSize);
        LOGGER.info("预约信息查询状态：查询成功");
        return CommonResult.success(CommonPage.restPage(pageResult));
    }
    /**
     * 根据房间id获取所有的预约时间
     * @param id
     * @return
     */
    @ApiOperation("根据房间id获取所有的预约时间")
    @RequestMapping(value = "/getTimeByRoomId/{id}", method = RequestMethod.GET)
    @PreAuthorize("hasAnyAuthority('user','admin')")
    public CommonResult getTimeByRoomId(@PathVariable("id") Long id) {
        return appointmentService.getTimeByRoomId(id);
    }

    /**
     * 删除预约信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除预约信息")
    @RequestMapping(value = "/deleteAppointment/{id}", method = RequestMethod.DELETE)
    @PreAuthorize("hasAuthority('admin')")
    public CommonResult deleteAppointment(@PathVariable Long id) {
        appointmentService.removeById(id);
        LOGGER.info("删除预约信息成功");
        return CommonResult.success("删除预约信息成功");
    }

    /**
     * 添加预约时间
     * @param
     * @return
     */
//    @ApiOperation(value = "添加预约时间")
//    @RequestMapping(value = "/addOrderTime", method = RequestMethod.POST)
//    @PreAuthorize("hasAnyAuthority('user','admin')")
//    public CommonResult addOrderTime(@RequestBody TimeDTO timeDTO) {
//        return appointmentService.addOrderTime(timeDTO);
//    }
}
